﻿using System; 
using GlobalTripleJump;
using TMPro;
using UnityEngine; 

namespace TripleJump {
    public class CCurrentDistanceTips {
        public Transform root;

        TextMeshPro distanceText;

        public void Init() {
            var gg = C128_AssetsCore.GetModel(GlobalTripleJumpCfg.artPath_currDistanceTips, 1);
            this.root = gg.transform;
            distanceText = root.transform.Find("text").GetComponent<TextMeshPro>();
            root.gameObject.SetActive(false);
        }

        int o_roloId;

        public void GameReset(int roloId) {
            this.o_roloId = roloId;
            distanceText.color = Color.white;
            //Debug.LogErrorFormat("显示纪录______lll___");
            IsShow(false);
        }

        bool isShow;

        public void IsShow(bool isShow) {
            this.isShow = isShow;
            root.gameObject.SetActive(isShow);
            //distanceText.materialForRendering.SetColor("_FaceColor", Color.white);
        }

        public void SetShow(Vector3 point, Vector3 normal, float distance) {
            if (isShow == false) {
                return;
            }
            //Debug.LogErrorFormat("_C_RolePosiRing______________________{0}____", distance);
            root.transform.position = point + normal * 0.1f;
            root.transform.rotation = Quaternion.FromToRotation(Vector3.forward, new Vector3(normal.x, -normal.z, normal.y));
            distanceText.text = distance.ToString("0.0m");
        }

        public void ShowNewRecordTips(int roloId, float currentDistance) {
            //Debug.LogErrorFormat("显示新纪录_________");
            if (o_roloId == roloId) {
                //distanceText.materialForRendering.SetColor("_FaceColor", Color.yellow);
                distanceText.color = Color.yellow;
            }
        }
    }
}
